import os, time
from pprint import pprint
from myglsl import glslFiles, glslTitles


# pprint(glslFiles)
print(f'glslFiles len is {len(glslFiles)}')

index = 0
total = len(glslFiles)
for glsefile in glslFiles:

    ffmpegcmd = f'ffmpeg -t 3 -loop 1 -i 1.jpg -t 3 -loop 1 -i 2.jpg  -filter_complex "gltransition=offset=1.0:duration=2.0:source={glsefile}" -y output/{index}.mp4'
    # time.sleep(1)
    # showText = f'{glslTitles[index]} Transition Effect'.capitalize()
    showText = f'{glslTitles[index]} Transition Effect ( {index}/{total} )'.title()
    print(showText)
    os.system(ffmpegcmd)
    print(f'{ffmpegcmd}')
    ffmpegTextCmd = f"ffmpeg -y -i output/{index}.mp4 -vf \"format=yuv444p,drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=fill,drawtext=fontfile=open-sans/OpenSans-Regular.ttf:text='{showText}':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,format=yuv420p'\" -c:v libx264 -c:a copy -movflags +faststart outputtext/{index}.mp4"
    os.system(ffmpegTextCmd)
    index =  index + 1


# with open('list.txt','w') as f:
#     index = 0
#     for glsefile in glslFiles:
#         f.write(f'file outputtext/{index}.mp4\r\n')
#         index =  index + 1




# find *.mp4 | sed 's:\ :\ :g'| sed 's/^/file /' > list.txt
# ffmpeg -safe 0 -f concat -i list.txt -c copy video-merge.mp4
